package com.oi.test01.hw2;
import com.oi.test01.entity.Student;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;

/**
 * @author bin
 * @date 2025 - 03 -25
 **/
public class MainTest02 {
    public static void main(String[] args) throws Exception {
        Student stu = new Student();
        stu.setName("张三");
        System.out.println(getProperty(stu, "name"));
    }
    public static Object getProperty(Object bean,String proper) throws Exception{
        PropertyDescriptor propertyDescriptor = new PropertyDescriptor(proper, bean.getClass());
        Method readMethod = propertyDescriptor.getReadMethod();
        return readMethod.invoke(bean);
    }
}
